<cfcomponent output="false">
	<cfset this.name = "SmugSettings_CFSmugAPITest" />
	<cfset this.applicationTimeout = createTimeSpan(0,2,0,0) />
	<cfset this.clientManagement = false />
	<cfset this.clientStorage = "cookie" />
	<cfset this.loginStorage = "session" />
	<cfset this.sessionManagement = true />
	<cfset this.sessionTimeout = createTimeSpan(0,0,20,0) />
	<cfset this.setClientCookies = true />
	<cfset this.setDomainCookies = false />
	<cfset this.scriptProtect = true />

	<cffunction name="onApplicationStart" returnType="boolean" output="false">

		<cfset var smugConfig = createObject( "component", "smug.CFSmugConfig" ).init( APIKey = "YOUR-API-KEY",
 																			 	 	   userAgent = "SmugSettings $Revision$",
 																			 	 	   debugEnabled = false ) />

		<cfscript>
			Application.config = StructNew();
			Application.config.appUrlName = "SmugSettings";
			Application.config.appBaseName = "SmugSettings";
			Application.config.FileSeparator = createObject("java","java.io.File").separator;

/*
			Application.cfc.action = StructNew();
			Application.cfc.action.authAction = createObject( "component", "action.authAction" ).init( smugConfig = smugConfig);
			Application.cfc.action.userAction = createObject( "component", "action.userAction" ).init( smugConfig = smugConfig);
			Application.cfc.action.subCategoryAction = createObject( "component", "action.subCategoryAction" ).init( smugConfig = smugConfig);
*/

			Application.cfc.smugAuth = createObject( "component", "smug.CFSmugAuth" ).init( config = smugConfig );
			Application.cfc.smugAlbums = createObject( "component", "smug.CFSmugAlbums" ).init( config = smugConfig );
			Application.cfc.smugCategories = createObject( "component", "smug.CFSmugCategories" ).init( config = smugConfig );
			Application.cfc.smugSubCategories = createObject( "component", "smug.CFSmugSubCategories" ).init( config = smugConfig );
			Application.cfc.smugImages = createObject( "component", "smug.CFSmugImages" ).init( config = smugConfig );
			Application.cfc.smugUsers = createObject( "component", "smug.CFSmugUsers" ).init( config = smugConfig );

		</cfscript>

		<cfreturn true />
	</cffunction>

	<cffunction name="onApplicationEnd" returnType="void" output="false">
		<cfargument name="applicationScope" required="true" />
	</cffunction>

	<cffunction name="onRequestStart" returnType="boolean" output="false">
		<cfargument name="thePage" type="string" required="true" />

		<cfset structAppend( Request, url, true ) />
		<cfset structAppend( Request, form, true ) />

		<cfif StructKeyExists( Request, "refreshApp") or true>
			<cfset onApplicationStart() />
		</cfif>

		<cflock scope="Session" timeout="60">
			<cfparam name="Session.user.loggedIn" default="false" />
		</cflock>

		<cfparam name="Request.doAction" default="" />

		<!--- Check for login here --->
		<cfif Not Session.user.loggedIn And Not FindNoCase( "auth.login.", Request.doAction )>
			<cflocation url="./action.cfm?doAction=auth.login.view" addtoken="false" />
		</cfif>

		<cfset this.start = now() />

		<cfreturn true />
	</cffunction>


	<cffunction name="onRequest" returnType="void">
		<cfargument name="thePage" type="string" required="true" />
		<cfset var dir = GetDirectoryFromPath( Arguments.thePage ) />
		<cfset var depthApp = ListFind( dir, Application.config.appUrlName, "/" ) />
		<cfset var pageDepth = ( ListLen(Arguments.thePage, "/" ) - 1 ) - depthApp />
		<cfset var i = 0 />

		<cfloop from="1" to="#depthApp#" index="i">
			<cfset Arguments.thePage = ListRest( Arguments.thePage, "/" ) />
		</cfloop>

		<cfinclude template="./common/_header.cfm" />
		<cfinclude template="#Arguments.thePage#" />
		<cfinclude template="./common/_footer.cfm" />

	</cffunction>


	<cffunction name="onRequestEnd" returnType="void" output="false">
		<cfargument name="thePage" type="string" required="true" />

		<cflock scope="Session" timeout="60">
			<cfset Session.messages.errors = ArrayNew( 1 ) />
			<cfset Session.messages.success = ArrayNew( 1 ) />
		</cflock>
	</cffunction>

	<cffunction name="onError" output="true">
		<cfargument name="exception" required="true" />
		<cfargument name="eventName" type="string" required="true" />
		<!--- Log all errors --->


		<!--- Display an error message if there is a page context. --->
		<cfif ( trim( Arguments.eventName ) neq "onSessionEnd" ) AND
			  ( trim( Arguments.eventName ) neq "onApplicationEnd" )>

			<cflog file="#this.name#" type="error"
				   text="Event name: #Arguments.eventName#" />

			<cflog file="#this.name#" type="error"
				   text="Message: #Arguments.exception.message#" />

			<cfoutput>
				<h2>An unexpected error occurred.</h2>
				<p>Please provide the following information to technical support:</p>
				<p>Error Event: #Arguments.eventName#</p>
				<p>Error details:</p>
			</cfoutput>

			<cfdump var="#Arguments.exception#" />

		<cfelseif ( Arguments.eventName eq "onApplicationEnd" )>
			<cflog file="#this.name#" type="Information"
				   text="Application #this.name# Ended" />
		</cfif>
	</cffunction>

	<cffunction name="onSessionStart" returnType="void" output="false">

	</cffunction>

	<cffunction name="onSessionEnd" returnType="void" output="false">
		<cfargument name="sessionScope" type="struct" required="true" />
		<cfargument name="appScope" type="struct" required="false" />
	</cffunction>
</cfcomponent>